package com.cee.admin.config.shiro;

import lombok.Data;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.authz.Permission;

import java.io.Serializable;

/**
 * 默认的配置规则是包含的匹配 例如
 * 匹配sys:user:add 当有sys:user权限的时候就会通过 这不是我们想要的
 * 我们要的是完全sys:user:add才有权限
 */
@Data
public class WholePermission implements Permission, Serializable {

    private String permissionString;

    public WholePermission(String permissionString) {
        this.permissionString = permissionString;
    }

    @Override
    public boolean implies(Permission p) {
        if (!(p instanceof WholePermission)) {
            return false;
        }
        WholePermission wp = (WholePermission) p;
        return StringUtils.isNotBlank(permissionString) && permissionString.equals(wp.getPermissionString());
    }
}
